package org.geoscrape;

public enum LogType
{
	ANNOUNCEMENT,
	ATTENDED,
	WILL_ATTEND,
	RETRACT_LISTING,
	FOUND_IT,
	DID_NOT_FIND,
	WRITE_NOTE,
	NEEDS_ARCHIVED,
	NEEDS_MAINTENANCE,
	UNARCHIVED,
	PUBLISH_LISTING,
	ENABLE_LISTING,
	DISABLED,
	OWNER_MAINTENANCE,
	WEBCAM_PHOTO_TAKEN,
	UPDATE_COORDINATES,
	POST_REVIEWER_NOTE,
	UNARCHIVE,
	ARCHIVE;

	public static LogType parse(String type)
	{
		try
		{
			String convertedType = type.toUpperCase();
			convertedType = convertedType.replaceAll(" ", "_");
			convertedType = convertedType.replaceAll("\\!", "");
			convertedType = convertedType.replaceAll("-", "");
			convertedType = convertedType.replaceAll("/", "");
			convertedType = convertedType.replaceAll("\\\\", "_");
			LogType res = LogType.valueOf(convertedType);
			return res;
		}
		catch (IllegalArgumentException e)
		{
			// not found
		}
		if (type.equals("Didn't find it"))
		{
			return DID_NOT_FIND;
		}
		else if (type.equals("Temporarily Disable Listing"))
		{
			return DISABLED;
		}
		else
		{
			System.out.println("Don't know log type \"" + type + "\"");
			return null;
			// throw new IllegalArgumentException("Don't know log type \"" +
			// type +"\"");
		}
	}

	public String getText()
	{
		String res = "";
		if(this.equals(DID_NOT_FIND))
		{
			res = "Didn't find it";
		}
		else if(this.equals(DISABLED))
		{
			res = "Temporarily Disable Listing";
		}
		else
		{
			res = this.name();
			res = res.replaceAll("_", " ");
			res = res.toLowerCase();
			res = res.substring(0,1).toUpperCase()+res.substring(1);
		}
		return res;
	}
}
